//
//  PopWindowHelper.swift
//  d11
//
//  Created by peale on 2018/7/25.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit

@objc protocol Pay{
    func pay(data:[String:Any],name:String,card:String)
   }

class PopWindowHelper:NSObject,UITextFieldDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return UITableViewCell.init()
    }
    
//高 290 转账  存款505
   
    static func dissmissPopView(tag : Int){
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.viewWithTag(tag)?.removeFromSuperview()
    }
    

 
   //客服弹窗
    static func showCustomerServicePopView(dict:[String:Any]?,bgView:UIView,isShowCallBack:Bool){
        print("我的数据\(dict)")
        
        var kefuCount = 0
        var popHeight = 330
        var dataArray = [["title":"自助客服","icon":"icon_kefu_cell_information"],  ["title":"客户端下载","icon":"icon_kefu_cell_dowload"]]
        let topDict = dict?["top"] as? [String : Any] ?? [:]
        let topStatus = topDict["status"] as? String ?? "0"
        let topTitle = topDict["title"] as? String ?? ""
        let topUrl = topDict["dropdownlist"] as? String ?? ""
    
        let bottomDict = dict?["bottom"] as? [String : Any] ?? [:]
        let bottomStatus = bottomDict["status"] as? String ?? "0"
        let bottomTitle = bottomDict["title"] as? String ?? ""
        let bottomUrl = bottomDict["dropdownlist"] as? String ?? ""
        if topStatus != "0"{
            kefuCount += 1
            dataArray.append(["title":topTitle,"icon":"icon_kefu_cell_kefu","url":topUrl])
        }else{
            popHeight -= 55
        }
        if bottomStatus != "0"{
            kefuCount += 1
            dataArray.append(["title":bottomTitle,"icon":"icon_kefu_cell_kefu","url":bottomUrl])
        }else{
            popHeight -= 55
        }
        if isShowCallBack == true{
              dataArray.append(["title":"电话回拨","icon":"icon_kefu_cell_callback"])
        }else{
            popHeight -= 55
        }
      
//        let bgView :UIView  = UIView.init()
//        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
//        bgView.tag = 1200
//        bgView.isUserInteractionEnabled = true
//        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PopWindowHelper.closeShowCustomerServicePopView))
//       // tapGesture.delegate = bgView.self as? UIGestureRecognizerDelegate
//        tapGesture.numberOfTapsRequired = 1
//        tapGesture.delegate = self
//        bgView.addGestureRecognizer(tapGesture)
        
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        let effecView = UIHelper.showBlurEffect(isClick:true)
        window.addSubview(effecView)
//        let bgView = self.showBgView()
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.isUserInteractionEnabled = true
           whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
//            whiteView.isUserInteractionEnabled = true;
//            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(layoutMiss))
//            tapGesture.numberOfTapsRequired = 1
//            whiteView.addGestureRecognizer(tapGesture)
            let layerGradient = CAGradientLayer()
             layerGradient.colors = [
                 UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
                 UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
             ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: Int(kScreenWidth-100), height: popHeight)
            whiteView.layer.addSublayer(layerGradient)
            whiteView.layer.cornerRadius = 5;
            whiteView.layer.masksToBounds = true
            //bgView 透明背景色  whiteView 是黄色的背景色
            bgView.addSubview(whiteView)
            whiteView.snp.makeConstraints { (make) in
                make.left.equalToSuperview().offset(50)
                make.right.equalToSuperview().offset(-50)
                make.centerY.equalToSuperview()
                make.centerX.equalToSuperview()
                make.height.equalTo(popHeight)
            }
        let titleLabel = UILabel.init()
        titleLabel.textAlignment = .center
        titleLabel.textColor = UIColor.white
        titleLabel.text = "请选择客服"
        titleLabel.font = UIFont.systemFont(ofSize: 18)
        whiteView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.centerX.equalToSuperview()
            make.height.equalTo(44)
            make.top.equalToSuperview().offset(5)
         }
        
        let serviceView =  MXCustomerServicePopView.init(frame: CGRect(x: 10, y: 0, width: Int(kScreenWidth-100-20), height: popHeight-44-15), array: dataArray)
        serviceView.isUserInteractionEnabled=true
        serviceView.callChangeBlock { (index) in
            if index == 0{ //自助客服
                PopWindowHelper.continueWithSelf()
            }else if index == 1{ //客户端下载
                PopWindowHelper.downloadAPP()
            }else if index == 2{ //在线客服/专属客服/电话回拨
                if dataArray.count >= 4{//不管是 在线客服/专属客服 直接从数组取url 和 title跳转到webview页面
                    UIHelper.removeEffect()
                    PopWindowHelper.dissmissPopView(tag: 1200)
                    let dict = dataArray[index]
                         print("我的最倒2个电话客服\(dict)")
                    PopWindowHelper.navigateWebView(toPath: dict["url"] ?? "", dict["title"] ?? "在线客服",sign: true)
                }else{ //电话回拨 原生页面
                    UIHelper.removeEffect()
                    PopWindowHelper.dissmissPopView(tag: 1200)
                    // 点击在线客服不需要登录
//                    if !UserHelper.getLoginStatus() {
//                        let topVc =  ToolHelper.getTopVC()
//                        if (topVc != nil) {
//                            LoginViewController.loginIfNeedController(currentController: topVc!) {}
//                        }
//                        return
//                    }
                    let vc = CallBackVC.init()
                    vc.hidesBottomBarWhenPushed = true
                    funcgetCurrentViewC().navigationController?.pushViewController(vc, animated: true)
//                    funcgetCurrentViewC().present(CallBackVC.init(), animated: true) {
//                        //打开完成
//                    }
                }
            }else if index == 3{ //专属客服/电话回拨
                let dict = dataArray[index]
                let title = dict["title"]!
                if(title.contains("电话")){
                    print("======电话回拨")
                    UIHelper.removeEffect()
                    PopWindowHelper.dissmissPopView(tag: 1200)
                    if !UserHelper.getLoginStatus() {
                        let topVc =  ToolHelper.getTopVC()
                        if (topVc != nil) {
                            LoginViewController.loginIfNeedController(currentController: topVc!) {}
                        }
                        return
                }
                let vc = CallBackVC.init()
                 vc.hidesBottomBarWhenPushed = true
                 funcgetCurrentViewC().navigationController?.pushViewController(vc, animated: true)
                }else{
                    if dataArray.count == 5{ //专属客服 直接从数组取url 和 title跳转到webview页面
                       UIHelper.removeEffect()
                       PopWindowHelper.dissmissPopView(tag: 1200)
                       print("我的最后一个电话客服\(dict)")
                       PopWindowHelper.navigateWebView(toPath: dict["url"] ?? "", dict["title"] ?? "在线客服",sign: true)
                   }else if(dataArray.count == 4){
                       UIHelper.removeEffect()
                       PopWindowHelper.dissmissPopView(tag: 1200)
                       print("我的最后一个电话客服\(dict)")
                       PopWindowHelper.navigateWebView(toPath: dict["url"] ?? "", dict["title"] ?? "在线客服",sign: true)
                   }else{ //电话回拨 原生页面
                       UIHelper.removeEffect()
                       PopWindowHelper.dissmissPopView(tag: 1200)
                       if !UserHelper.getLoginStatus() {
                           let topVc =  ToolHelper.getTopVC()
                           if (topVc != nil) {
                               LoginViewController.loginIfNeedController(currentController: topVc!) {}
                        }
                           return
                       }
                      let vc = CallBackVC.init()
                       vc.hidesBottomBarWhenPushed = true
                       funcgetCurrentViewC().navigationController?.pushViewController(vc, animated: true)
                   }
                }
                
            }else if index == 4{ //电话回拨 原生页面
                UIHelper.removeEffect()
                PopWindowHelper.dissmissPopView(tag: 1200)
                if !UserHelper.getLoginStatus() {
                    let topVc =  ToolHelper.getTopVC()
                    if (topVc != nil) {
                        LoginViewController.loginIfNeedController(currentController: topVc!) {}
                    }
                    return
                }
                let vc = CallBackVC.init()
                vc.hidesBottomBarWhenPushed = true
                funcgetCurrentViewC().navigationController?.pushViewController(vc, animated: true)
//                funcgetCurrentViewC().present(CallBackVC.init(), animated: true) {
                     //打开完成
//                 }
            }
        }
        whiteView.addSubview(serviceView)
        serviceView.snp.makeConstraints { (make) in
           make.left.equalToSuperview().offset(10)
           make.right.equalToSuperview().offset(-10)
           make.centerX.equalToSuperview()
           make.height.equalTo(popHeight-44-15)
           make.top.equalTo(titleLabel.snp.bottom)
        }
    }
    
  
   static func downloadAPP() {
        UIHelper.removeEffect()
        PopWindowHelper.dissmissPopView(tag: 1200)
        if (GlobalInfo.csDownClient != nil) {
             UIApplication.shared.openURL( URL(string: GlobalInfo.csDownClient ?? "")!)
        }else{
            UIApplication.shared.openURL( URL(string: "http://down.manbetxhbetxhbc.com")!)
        }
       
       
    }
    
   static func continueWithSelf(){
        UIHelper.removeEffect()
        PopWindowHelper.dissmissPopView(tag: 1200)
         if UserHelper.getLoginStatus() {
             if GlobalInfo.isCsAuto == nil || GlobalInfo.isCsAuto == false {
               //  self.showToast(text: "自助客服系统暂未开放", pos:.Bottom)
                UIHelper.alertSimpleMessage(about: "自助客服系统暂未开放", withDescription: "")
                 return
             }
         }else{
             let topVc =  ToolHelper.getTopVC()
             if (topVc != nil) {
                 LoginViewController.loginIfNeedController(currentController: topVc!) {}
            }
              return
         }
        var atcUrl = ""
         if UserHelper.getLoginStatus() {
             if let serviceSelfIurl=GlobalInfo.serviceSelfIurl{
                 atcUrl = serviceSelfIurl
             }else{
                 atcUrl = "https://" + UserDefaults.standard.string(forKey: DefaultKey.USER_DOMAIN)! + "/walletm/csIndex?isMobile=1"
             }
             PopWindowHelper.navigateWebView(toPath: atcUrl, "自助客服",sign: true)
         }else{
            let topVc =  ToolHelper.getTopVC()
            if topVc != topVc {
                LoginViewController.loginIfNeedController(currentController: topVc!) {}
            }
         }
     }
    
  static func navigateWebView(toPath: String, _ title: String,sign:Bool){
        
        let goNext: WebViewController = WebViewController.init()
        goNext.url = toPath
        goNext.title = title
    
        goNext.signLoging=sign
        goNext.isKefu = true
        goNext.hidesBottomBarWhenPushed = true
        funcgetCurrentViewC().navigationController?.pushViewController(goNext, animated: true)
    }
    
    @objc static func closeShowCustomerServicePopView(){
        UIHelper.removeEffect()
        PopWindowHelper.dissmissPopView(tag: 1200)
    }
    
    //回拨号码
     static func continueWithNumber(){
        UIHelper.removeEffect()
               PopWindowHelper.dissmissPopView(tag: 1200)
        let urlString = "tel://"+(GlobalInfo.isCallbackPhone ?? "")
           if let url = URL(string: urlString) {
               //根据iOS系统版本，分别处理
               if #available(iOS 10, *) {
                   UIApplication.shared.open(url, options: [:],
                                             completionHandler: {
                                               (success) in
                   })
               } else {
                   UIApplication.shared.openURL(url)
               }
           }
       }
 
    //登录提醒
    static func showLoginPopView(){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1111
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        let effecView = UIHelper.showBlurEffect(isClick:true)
        window.addSubview(effecView)
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(252)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle("登录提醒", for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        let content =  UILabel.init()
        content.text = "此功能仅对注册用户开放!"
        content.textColor =  HexRGBAlpha(0x333333,1)
        content.textAlignment = .center
        content.font = UIFont.systemFont(ofSize: 16)
        whiteView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(90)
            make.left.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom)
        }
        
         let cancelBtn : UIButton  = UIButton.init(type: .custom)
         cancelBtn.setTitle("知道了", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToCancel), for: .touchUpInside)
         whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-60)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(content.snp.bottom)
        }
        
        let loginBtn : UIButton  = UIButton.init(type: .custom)
        let attributedString = NSMutableAttributedString(string:"")
        let attrs = [NSAttributedString.Key.font.rawValue :UIFont.systemFont(ofSize:17.0),
                     NSAttributedString.Key.foregroundColor :UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1),
                     NSAttributedString.Key.underlineStyle :1] as! [NSAttributedString.Key : Any]
        let Setstr  = NSMutableAttributedString.init(string: "登录", attributes: attrs)
        attributedString.append(Setstr)
        loginBtn.setAttributedTitle(attributedString, for: .normal)
         loginBtn.addTarget(self, action: #selector(self.actionToLogin), for: .touchUpInside)
        whiteView.addSubview(loginBtn)
        loginBtn.snp.makeConstraints { (make) in
            make.width.equalTo(70)
            make.height.equalTo(40)
            make.left.equalToSuperview()
            make.bottom.equalToSuperview().offset(-10)
        }
        
        let registerBtn : UIButton  = UIButton.init(type: .custom)
        let attributedString2 = NSMutableAttributedString(string:"")
        let Setstr2  = NSMutableAttributedString.init(string: "注册", attributes: attrs)
        attributedString2.append(Setstr2)
        registerBtn.setAttributedTitle(attributedString2, for: .normal)
        registerBtn.addTarget(self, action: #selector(self.actionRegister), for: .touchUpInside)
        whiteView.addSubview(registerBtn)
        registerBtn.snp.makeConstraints { (make) in
            make.width.equalTo(70)
            make.height.equalTo(40)
            make.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-10)
        }
    }
   
    @objc static func actionToCancel(){
         UIHelper.removeEffect()
          PopWindowHelper.dissmissPopView(tag: 1111)
    }
    
    @objc static func actionToLogin(){
         UIHelper.removeEffect()
          PopWindowHelper.dissmissPopView(tag: 1111)
         setRootLoginVC()

    //    GlobalInfo.mainTabBarController?.navigationController?.popToRootViewController(animated: true)
    }
    @objc static func actionRegister(){
         UIHelper.removeEffect()
        PopWindowHelper.dissmissPopView(tag: 1111)
        setRootLoginVC()
      //  GlobalInfo.mainTabBarController?.navigationController?.popToRootViewController(animated: true)
        UserDefaults.standard.set(true, forKey: DefaultKey.TO_PAGE_REGISET)
        NotificationCenter.default.post(name: NSNotification.Name(kNotificationToRegisterPage), object: self, userInfo: ["msg":kNotificationToRegisterPage])
    }
    
    
    
    //最新版本
    static func showNewVersionPopView(title : NSString,subTitle : NSString){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1112
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(225)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        let content =  UILabel.init()
        content.text = subTitle as String
        content.textColor =  HexRGBAlpha(0x333333,1)
        content.textAlignment = .center
        content.font = UIFont.systemFont(ofSize: 16)
        whiteView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(91)
            make.left.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom)
        }
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("知道了", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToNewVersionCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(content.snp.bottom).offset(12)
        }
    }
    
    @objc static func actionToNewVersionCancel(){
        PopWindowHelper.dissmissPopView(tag: 1112)
    }
    
    
    //站内信
    static func showMsgPopView(title : NSString,subTitle : NSString){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1113
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(282.5)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        let content =  UITextView.init()
        if #available(iOS 11.0, *) {
            content.contentInsetAdjustmentBehavior = .never
        } else {
            // Fallback on earlier versions
        }
        content.text = subTitle as String
        content.textColor =  HexRGBAlpha(0x333333,1)
        content.textAlignment = .left
        content.isEditable = false
//        content.numberOfLines = 0
//        content.adjustsFontSizeToFitWidth = true
//        content.minimumScaleFactor = 0.8
        content.font = UIFont.systemFont(ofSize: 14)
        whiteView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-50)
            make.height.equalTo(165)
            make.centerX.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom)
        }
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("知道了", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToMsgCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(content.snp.bottom)
        }
    }
    
    
    @objc static func actionToMsgCancel(){
        PopWindowHelper.dissmissPopView(tag: 1113)
        
        
    }
    //174 233   92.5
   // 20+12.5 33.5
  // 60 5*30 = 150 = 210 +30+40+22.5 240+40 22.5
    //转账记录575 20 20  10+20 10+20 10+20 10+20  10+20  30
    //存/取款记录
    static func showAmountRecordPopView(title : NSString,msg : [String : Any]){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1114
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(325)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        let noStr     = "单号             \(msg["dno"] ?? "")"
        let money1Str = "申请金额      \(msg["amount"] ?? "")"
        let money2Str = "实际金额      \(msg["actual"] ?? "")"
        let timeStr   = "时间             \(msg["created"] ?? "")"
        let statusStr = "状态             \(msg["status"] ?? "")"
        let noLabel =  UILabel.init()
        noLabel.textAlignment = .left
        noLabel.textColor =  HexRGBAlpha(0x666666,1)
        noLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString = noLabel.attributedTextColorWithString(string: noStr as NSString, subString: "单号", color: UIColor.black)
       noLabel.attributedText = noLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString, string: noStr as NSString, subString: "单号", font: UIFont.systemFont(ofSize: 14))
//        noLabel.adjustsFontSizeToFitWidth = true
//        noLabel.minimumScaleFactor = 0.7
        whiteView.addSubview(noLabel)
        noLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom).offset(20)
        }
        
        let money1Label =  UILabel.init()
         money1Label.textAlignment = .left
        money1Label.textColor = HexRGBAlpha(0x666666,1)
//        money1Label.adjustsFontSizeToFitWidth = true
//        money1Label.minimumScaleFactor = 0.7
        money1Label.font = UIFont.systemFont(ofSize: 14)
        let attributedString2 = money1Label.attributedTextColorWithString(string: money1Str as NSString, subString: "申请金额", color: UIColor.black)
        money1Label.attributedText = money1Label.attributedTextFontAddWithAttributedString(attributedString: attributedString2, string: money1Str as NSString, subString: "申请金额", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(money1Label)
        money1Label.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(noLabel.snp.bottom).offset(12.5)
        }
        
        let money2Label =  UILabel.init()
         money2Label.textAlignment = .left
        money2Label.textColor =  HexRGBAlpha(0x666666,1)
        //        money2Label.adjustsFontSizeToFitWidth = true
        //        money2Label.minimumScaleFactor = 0.7
        money2Label.font = UIFont.systemFont(ofSize: 14)
        let attributedString3 = money2Label.attributedTextColorWithString(string: money2Str as NSString, subString: "实际金额", color: UIColor.black)
        money2Label.attributedText = money2Label.attributedTextFontAddWithAttributedString(attributedString: attributedString3, string: money2Str as NSString, subString: "实际金额", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(money2Label)
        money2Label.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(money1Label.snp.bottom).offset(12.5)
        }
        
        let timeLabel =  UILabel.init()
         timeLabel.textAlignment = .left
        timeLabel.textColor =  HexRGBAlpha(0x666666,1)
        //        timeLabel.adjustsFontSizeToFitWidth = true
        //        timeLabel.minimumScaleFactor = 0.7
        timeLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString4 = timeLabel.attributedTextColorWithString(string: timeStr as NSString, subString: "时间", color: UIColor.black)
        timeLabel.attributedText = timeLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString4, string: timeStr as NSString, subString: "时间", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(money2Label.snp.bottom).offset(12.5)
        }
        
        let statusLabel =  UILabel.init()
        statusLabel.textAlignment = .left
        statusLabel.textColor =  HexRGBAlpha(0x666666,1)
        //        statusLabel.adjustsFontSizeToFitWidth = true
        //        statusLabel.minimumScaleFactor = 0.7
        statusLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString5 = statusLabel.attributedTextColorWithString(string: statusStr as NSString, subString: "状态", color: UIColor.black)
        statusLabel.attributedText = statusLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString5, string: statusStr as NSString, subString: "状态", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(statusLabel)
        statusLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(timeLabel.snp.bottom).offset(12.5)
        }
        
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("知道了", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToAmountRecordgCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(statusLabel.snp.bottom).offset(30)
        }
    }

    @objc static func actionToAmountRecordgCancel(){
        PopWindowHelper.dissmissPopView(tag: 1114)
    }
    
    //转账记录
    static func showTransferRecordPopView(title : NSString,msg : [String : Any]){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1115
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(260)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        let noStr     = "单号             \(msg["dno"] ?? "")"
        let money1Str = "金额             \(msg["transamount"] ?? "")"
        let timeStr   = "时间             \(msg["created"] ?? "")"
        let noLabel =  UILabel.init()
        noLabel.textAlignment = .left
        noLabel.textColor =  HexRGBAlpha(0x666666,1)
        noLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString = noLabel.attributedTextColorWithString(string: noStr as NSString, subString: "单号", color: UIColor.black)
        noLabel.attributedText = noLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString, string: noStr as NSString, subString: "单号", font: UIFont.systemFont(ofSize: 14))
        //        noLabel.adjustsFontSizeToFitWidth = true
        //        noLabel.minimumScaleFactor = 0.7
        whiteView.addSubview(noLabel)
        noLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom).offset(20)
        }
        
        let money1Label =  UILabel.init()
        money1Label.textAlignment = .left
        money1Label.textColor = HexRGBAlpha(0x666666,1)
        //        money1Label.adjustsFontSizeToFitWidth = true
        //        money1Label.minimumScaleFactor = 0.7
        money1Label.font = UIFont.systemFont(ofSize: 14)
        let attributedString2 = money1Label.attributedTextColorWithString(string: money1Str as NSString, subString: "申请金额", color: UIColor.black)
        money1Label.attributedText = money1Label.attributedTextFontAddWithAttributedString(attributedString: attributedString2, string: money1Str as NSString, subString: "申请金额", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(money1Label)
        money1Label.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(noLabel.snp.bottom).offset(12.5)
        }
        
        let timeLabel =  UILabel.init()
        timeLabel.textAlignment = .left
        timeLabel.textColor =  HexRGBAlpha(0x666666,1)
        //        timeLabel.adjustsFontSizeToFitWidth = true
        //        timeLabel.minimumScaleFactor = 0.7
        timeLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString4 = timeLabel.attributedTextColorWithString(string: timeStr as NSString, subString: "时间", color: UIColor.black)
        timeLabel.attributedText = timeLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString4, string: timeStr as NSString, subString: "时间", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(money1Label.snp.bottom).offset(12.5)
        }
        
        
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("确定", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToTransferRecordgCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(timeLabel.snp.bottom).offset(30)
        }
    }
    
    @objc static func actionToTransferRecordgCancel(){
        PopWindowHelper.dissmissPopView(tag: 1115)
    }
    
    static func showLiushuiPopView(title : NSString,msg : [String : Any]){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1120
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(325)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        let noStr     = "平台             \(msg["gp"] ?? "")"
        let money1Str = "单号             \(msg["dno"] ?? "")"
        let money2Str = "类型             \(msg["type"] ?? "")"
        let timeStr   = "金额             \(msg["money"] ?? "")"
        let statusStr = "时间             \(msg["time"] ?? "")"
        let noLabel =  UILabel.init()
        noLabel.textAlignment = .left
        noLabel.textColor =  HexRGBAlpha(0x666666,1)
        noLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString = noLabel.attributedTextColorWithString(string: noStr as NSString, subString: "平台", color: UIColor.black)
        noLabel.attributedText = noLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString, string: noStr as NSString, subString: "平台", font: UIFont.systemFont(ofSize: 14))
        //        noLabel.adjustsFontSizeToFitWidth = true
        //        noLabel.minimumScaleFactor = 0.7
        whiteView.addSubview(noLabel)
        noLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom).offset(20)
        }
        
        let money1Label =  UILabel.init()
        money1Label.textAlignment = .left
        money1Label.textColor = HexRGBAlpha(0x666666,1)
        //        money1Label.adjustsFontSizeToFitWidth = true
        //        money1Label.minimumScaleFactor = 0.7
        money1Label.font = UIFont.systemFont(ofSize: 14)
        let attributedString2 = money1Label.attributedTextColorWithString(string: money1Str as NSString, subString: "单号", color: UIColor.black)
        money1Label.attributedText = money1Label.attributedTextFontAddWithAttributedString(attributedString: attributedString2, string: money1Str as NSString, subString: "单号", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(money1Label)
        money1Label.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(noLabel.snp.bottom).offset(12.5)
        }
        
        let money2Label =  UILabel.init()
        money2Label.textAlignment = .left
        money2Label.textColor =  HexRGBAlpha(0x666666,1)
        //        money2Label.adjustsFontSizeToFitWidth = true
        //        money2Label.minimumScaleFactor = 0.7
        money2Label.font = UIFont.systemFont(ofSize: 14)
        let attributedString3 = money2Label.attributedTextColorWithString(string: money2Str as NSString, subString: "类型", color: UIColor.black)
        money2Label.attributedText = money2Label.attributedTextFontAddWithAttributedString(attributedString: attributedString3, string: money2Str as NSString, subString: "类型", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(money2Label)
        money2Label.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(money1Label.snp.bottom).offset(12.5)
        }
        
        let timeLabel =  UILabel.init()
        timeLabel.textAlignment = .left
        timeLabel.textColor =  HexRGBAlpha(0x666666,1)
        //        timeLabel.adjustsFontSizeToFitWidth = true
        //        timeLabel.minimumScaleFactor = 0.7
        timeLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString4 = timeLabel.attributedTextColorWithString(string: timeStr as NSString, subString: "金额", color: UIColor.black)
        timeLabel.attributedText = timeLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString4, string: timeStr as NSString, subString: "金额", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(money2Label.snp.bottom).offset(12.5)
        }
        
        let statusLabel =  UILabel.init()
        statusLabel.textAlignment = .left
        statusLabel.textColor =  HexRGBAlpha(0x666666,1)
        //        statusLabel.adjustsFontSizeToFitWidth = true
        //        statusLabel.minimumScaleFactor = 0.7
        statusLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString5 = statusLabel.attributedTextColorWithString(string: statusStr as NSString, subString: "时间", color: UIColor.black)
        statusLabel.attributedText = statusLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString5, string: statusStr as NSString, subString: "时间", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(statusLabel)
        statusLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(timeLabel.snp.bottom).offset(12.5)
        }
        
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("知道了", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToLiushuiCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(statusLabel.snp.bottom).offset(30)
        }
    }
    @objc static func actionToLiushuiCancel(){
        PopWindowHelper.dissmissPopView(tag: 1120)
    }
    static func showBettingRecordPopView(title : NSString,msg : [String : Any]){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1116
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)

        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        let scroll = UIScrollView()
      
        let gameStr   = "游戏       \(msg["bet_content"] ?? "" )"
        let noStr     = "单号       \(msg["bet_no"] ?? "")"
        let betamtStr = "下注       \(msg["betamt"] ?? "")"
        let winStr    = "输赢       \(msg["win"] ?? "")"
        let statusStr = "状态       \(msg["settleName"] ?? "")"
        let timeStr   = "时间       \(msg["bettime"] ?? "")"
        let amtStr    = "流水       \(msg["valid_amt"] ?? "")"
        let payStr    = "派彩       \(msg["payout"] ?? "")"
        
        let gameLabel =  UILabel.init()
        gameLabel.textAlignment = .left
        gameLabel.textColor =  HexRGBAlpha(0x666666,1)
        gameLabel.font = UIFont.systemFont(ofSize: 14)
        gameLabel.numberOfLines = 0
        let grect =  gameLabel.getLableSize(text: gameStr, maxWidth: 250)
        var gheight : CGFloat = 20
        if grect.height < gheight {
            gheight = 20
        }else
        {
            gheight = grect.height+5
        }
        
        let noLabel =  UILabel.init()
        noLabel.textAlignment = .left
        noLabel.textColor =  HexRGBAlpha(0x666666,1)
        noLabel.font = UIFont.systemFont(ofSize: 14)
        noLabel.numberOfLines = 2
       // noLabel.lineBreakMode =  NSLineBreakByCharWrapping
        let nrect =  noLabel.getLableSize(text: noStr, maxWidth: 250)
        var nheight : CGFloat = 20
        if nrect.height < nheight {
            nheight = 20
        }else
        {
            nheight = nrect.height+5
        }
        
        let whiteView :UIView  = UIView()
        bgView.addSubview(scroll)
        scroll.addSubview(whiteView)
        if #available(iOS 11.0, *) {
            scroll.contentInsetAdjustmentBehavior = .never
        } else {
            // Fallback on earlier versions
        }
        scroll.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(462-60+gheight-20+nheight).priority(250)
            make.height.lessThanOrEqualTo(ScreenHeight-2*(kStatusBarheight+44)-60).priority(500)
        }
        scroll.contentSize = CGSize(width: 1, height: 462-60+gheight-20+nheight)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
    //    bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.left.top.equalToSuperview()
            make.height.equalTo(462-60+gheight-20+nheight)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
 
        //32.5x3 20*3 = +60
        
       
        let attributedString = gameLabel.attributedTextColorWithString(string: gameStr as NSString, subString: "游戏", color: UIColor.black)
        gameLabel.attributedText = gameLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString, string: gameStr as NSString, subString: gameStr as NSString, font: UIFont.systemFont(ofSize: 14))
        
        whiteView.addSubview(gameLabel)
        gameLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(gheight)
            make.centerX.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom).offset(20)
        }
        
        let attributedString1 = noLabel.attributedTextColorWithString(string: noStr as NSString, subString: "单号", color: UIColor.black)
        noLabel.attributedText = noLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString1, string: noStr as NSString, subString: "单号", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(noLabel)
        noLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(nheight)
            make.centerX.equalToSuperview()
            make.top.equalTo(gameLabel.snp.bottom).offset(12.5)
        }
        
        let betamtLabel =  UILabel.init()
        betamtLabel.textAlignment = .left
        betamtLabel.textColor = HexRGBAlpha(0x666666,1)
        betamtLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString2 = betamtLabel.attributedTextColorWithString(string: betamtStr as NSString, subString: "下注", color: UIColor.black)
        betamtLabel.attributedText = betamtLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString2, string: betamtStr as NSString, subString: "下注", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(betamtLabel)
        betamtLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(noLabel.snp.bottom).offset(12.5)
        }
        
        let  winLabel =  UILabel.init()
         winLabel.textAlignment = .left
         winLabel.textColor =  HexRGBAlpha(0x666666,1)
        winLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString3 = winLabel.attributedTextColorWithString(string: winStr as NSString, subString: "输赢", color: UIColor.black)
        winLabel.attributedText = winLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString3, string: winStr as NSString, subString: "输赢", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(winLabel)
        winLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(betamtLabel.snp.bottom).offset(12.5)
        }
        
        let statusLabel =  UILabel.init()
        statusLabel.textAlignment = .left
        statusLabel.textColor =  HexRGBAlpha(0x666666,1)
        statusLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString4 = statusLabel.attributedTextColorWithString(string: statusStr as NSString, subString: "状态", color: UIColor.black)
        statusLabel.attributedText = statusLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString4, string: statusStr as NSString, subString: "状态", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(statusLabel)
        statusLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(winLabel.snp.bottom).offset(12.5)
        }
        
        let timeLabel =  UILabel.init()
        timeLabel.textAlignment = .left
        timeLabel.textColor =  HexRGBAlpha(0x666666,1)
        timeLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString5 = statusLabel.attributedTextColorWithString(string: timeStr as NSString, subString: "时间", color: UIColor.black)
        timeLabel.attributedText = statusLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString5, string: timeStr as NSString, subString: "时间", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(statusLabel.snp.bottom).offset(12.5)
        }
        
        let amtLabel =  UILabel.init()
        amtLabel.textAlignment = .left
        amtLabel.textColor =  HexRGBAlpha(0x666666,1)
        amtLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString6 = amtLabel.attributedTextColorWithString(string: amtStr as NSString, subString: "流水", color: UIColor.black)
        amtLabel.attributedText = amtLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString6, string: amtStr as NSString, subString: "流水", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(amtLabel)
        amtLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(timeLabel.snp.bottom).offset(12.5)
        }
        
        let payLabel =  UILabel.init()
        payLabel.textAlignment = .left
        payLabel.textColor =  HexRGBAlpha(0x666666,1)
        payLabel.font = UIFont.systemFont(ofSize: 14)
        let attributedString7 = amtLabel.attributedTextColorWithString(string: payStr as NSString, subString: "派彩", color: UIColor.black)
        payLabel.attributedText = amtLabel.attributedTextFontAddWithAttributedString(attributedString: attributedString7, string: payStr as NSString, subString: "派彩", font: UIFont.systemFont(ofSize: 14))
        whiteView.addSubview(payLabel)
        payLabel.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
            make.top.equalTo(amtLabel.snp.bottom).offset(12.5)
        }
        
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("知道了", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToBettingRecordgCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(payLabel.snp.bottom).offset(30)
        }
    }
    @objc static func actionToBettingRecordgCancel(){
        PopWindowHelper.dissmissPopView(tag: 1116)
    }
    
    
    //加载中..
    static func showLodingView(str:String? = "读取中...",view:UIView) ->UIView{
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = UIColor.clear
        bgView.tag = 1117
       // bgView.isUserInteractionEnabled = true
    //    let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
      //  let effecView = UIHelper.showBlurEffect(isClick:true)
    //  window.addSubview(effecView)
        view.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let contentView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        contentView.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
        contentView.layer.cornerRadius = 5;
        contentView.layer.masksToBounds = true
        bgView.addSubview(contentView)
        contentView.snp.makeConstraints { (make) in
            make.width.equalTo(120)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(60)
        }
        
        let content =  UILabel.init()
        content.text = str
        content.textColor =  UIColor.white
        content.textAlignment = .center
        content.font = UIFont.systemFont(ofSize: 12)
        contentView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(60)
            make.top.equalToSuperview()
            make.left.equalToSuperview()
        }
        
        return bgView
        
    }
    static func closeLoding(view:UIView){
        view.viewWithTag(1117)?.removeFromSuperview()
    }
    
    
    //支付提示
    static func showPayHintPopView(title : NSString,subTitle : NSString){
        let bgView :UIView  = UIView.init()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1118
        let window: UIWindow  = ((UIApplication.shared.delegate?.window)!)!
        window.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(225)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.setBackgroundImage(imageNamed("icon_common_pop_window_title_bg"), for: .normal)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
        titleBtn.titleEdgeInsets = UIEdgeInsets(top: -10,left: 0, bottom: 0, right: 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(59)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        
        let closeBtn : UIButton  = UIButton.init(type: .custom)
        closeBtn.setImage(imageNamed("icon_popwindows_close"), for: .normal)
        closeBtn.adjustsImageWhenHighlighted = false
        closeBtn.addTarget(self, action: #selector(self.actionToPayHintCancel), for: .touchUpInside)
        whiteView.addSubview(closeBtn)
        closeBtn.snp.makeConstraints { (make) in
            make.width.equalTo(14)
            make.height.equalTo(14)
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview().offset(10)
        }
        
        
        let content =  UILabel.init()
        content.text = "建议您请更换其他金额重新提交"
        content.textColor =  HexRGBAlpha(0x333333,1)
        content.textAlignment = .center
        content.font = UIFont.boldSystemFont(ofSize: 16)
        whiteView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(20)
            make.left.equalToSuperview()
            make.top.equalTo(titleBtn.snp.bottom).offset(20)
        }
        
        let subContent =  UILabel.init()
        subContent.text = subTitle as String
        subContent.textColor =  HexRGBAlpha(0x666666,1)
        subContent.textAlignment = .center
        subContent.numberOfLines = 0
        subContent.font = UIFont.systemFont(ofSize: 14)
        whiteView.addSubview(subContent)
        subContent.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(50)
            make.left.equalToSuperview()
            make.centerX.equalToSuperview()
            make.top.equalTo(content.snp.bottom)
        }
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("确定", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-20, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(self.actionToPayHintCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-20)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(subContent.snp.bottom).offset(12)
        }
    }
    
    @objc static func actionToPayHintCancel(){
        PopWindowHelper.dissmissPopView(tag: 1118)
    }
    
    
    var loginCodecallBack : ((String,String)->())?
    var logintestCode = UITextField()
    var codeImageView = UIImageView()
    var bgView = UIView()
    var viewself : UIView?
    var sessionid :String = ""
    func showlgoinCodePopView(title : String,subTitle : String,callBack:((String,String)->())!,superview:UIView){
        let tapgester = UITapGestureRecognizer(target: self, action: #selector(updateVerificationCode2))
        codeImageView.addGestureRecognizer(tapgester)
        codeImageView.isUserInteractionEnabled = true
        loginCodecallBack = callBack
        bgView = UIView()
        logintestCode = UITextField()
        bgView.backgroundColor = RGBAlpa(1,1,1,0.4)
        bgView.tag = 1140
        viewself = bgView
        superview.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
        }
        
        let whiteView :UIView  = UIView.init(frame: UIScreen.main.bounds)
        whiteView.backgroundColor = UIColor.init(white: 1, alpha: 1)
        whiteView.layer.cornerRadius = 5;
        whiteView.layer.masksToBounds = true
        bgView.addSubview(whiteView)
        whiteView.snp.makeConstraints { (make) in
            make.width.equalTo(280)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(270)
        }
        
        let  titleBtn : UIButton  = UIButton.init(type: .custom)
        titleBtn.backgroundColor = HexRGBAlpha(0x333333,1)
        titleBtn.setTitle(title as String, for: .normal)
        titleBtn.setTitleColor(HexRGBAlpha(0xffcc66,1), for: .normal)
        titleBtn.adjustsImageWhenHighlighted = false
       // titleBtn.titleEdgeInsets = UIEdgeInsetsMake(-10,0, 0, 0)
        whiteView.addSubview(titleBtn)
        titleBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(54)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
        }
        
//        let viewtext = UIView()
//        whiteView.addSubview(viewtext)
//
//        viewtext.snp.makeConstraints { (make) in
//            make.width.equalToSuperview().offset(-100)
//            make.height.equalTo(31)
//            make.left.equalToSuperview().offset(50)
//            make.top.equalTo(titleBtn.snp.bottom).offset(20)
//        }
//        viewtext.layer.cornerRadius = 5
//        viewtext.layer.borderColor = RGBAlpa(170,170,170,1).cgColor
//         viewtext.layer.borderWidth = 0.5
//        let line = UIView()
//        line.backgroundColor = UIColor.black
//        whiteView.addSubview(line)
//        line.snp.makeConstraints { (make) in
//            make.left.equalTo(viewtext)
//            make.right.equalTo(viewtext).offset(-62)
//            make.height.equalTo(1)
//            make.bottom.equalTo(viewtext)
//        }
//
//        let imageCode = UIImageView()
//        imageCode.image = UIImage(named: "code")
//        viewtext.addSubview(imageCode)
//
//        imageCode.snp.makeConstraints { (make) in
//            make.left.top.equalTo(5)
//            make.width.height.equalTo(21)
//        }
        whiteView.addSubview(codeImageView)
        //        viewtext.addSubview(codeImageView)
        //        viewtext.clipsToBounds = true
        codeImageView.snp.makeConstraints { (make) in
            make.top.equalTo(titleBtn.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
            make.width.equalTo(60)
            make.height.equalTo(35)
        }
        logintestCode.textColor =  HexRGBAlpha(0x333333,1)
        logintestCode.delegate = self
        logintestCode.keyboardType = .numbersAndPunctuation
        logintestCode.textAlignment = .center
        logintestCode.font = UIFont.systemFont(ofSize: 15)
        logintestCode.placeholder = "输入上面图片中内容"
        logintestCode.borderStyle = UITextField.BorderStyle.roundedRect
        whiteView.addSubview(logintestCode)
        logintestCode.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.height.equalTo(45)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.top.equalTo(codeImageView.snp.bottom).offset(20)
        }
   
        let content =  UILabel.init()
        content.text = subTitle
        content.textColor = UIColor.red
        content.textAlignment = .center
        content.font = UIFont.systemFont(ofSize: 13)
        whiteView.addSubview(content)
        content.snp.makeConstraints { (make) in
            make.height.equalTo(30)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.top.equalTo(logintestCode.snp.bottom)
        }
        
        let cancelBtn : UIButton  = UIButton.init(type: .custom)
        cancelBtn.setTitle("确定", for: .normal)
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: 280-60, height: 40)
        cancelBtn.layer.addSublayer(layerGradient)
        cancelBtn.layer.cornerRadius = 5;
        cancelBtn.layer.masksToBounds = true
        cancelBtn.addTarget(self, action: #selector(actionTolgoinCodeCancel), for: .touchUpInside)
        whiteView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-100)
            make.height.equalTo(40)
            make.centerX.equalToSuperview()
            make.top.equalTo(content.snp.bottom)
        }
        updateVerificationCode2()
    }
    @objc  func actionTolgoinCodeCancel(){
        if (loginCodecallBack != nil) {
            loginCodecallBack!(logintestCode.text!,sessionid)
        }
       viewself?.removeFromSuperview()
    }
    
   @objc func updateVerificationCode(){
        RequestHelper.get(atPath: "/service/verifycode", withCompletion: { data in
            let imageData:NSData = NSData(data: data)
            print("\(imageData)")
            // When from background thread, UI needs to be updated on main_queue
            DispatchQueue.main.async {
                self.codeImageView.image = UIImage(data: imageData as Data)
            }
        }, withError: { error in
             DispatchQueue.main.async {
                MBProgressHUD.showMessage("刷新验证码失败", to: self.bgView)
            }
        })
    }
    
   @objc func updateVerificationCode2(){
        NetWorkRequest(API.verifycode(url: "833656a"), completion: {(responseData,statusCode,strData) -> (Void) in
            DispatchQueue.main.async {
                 let dict =  responseData["data"].dictionaryValue
                 let imageStr =  dict["image"]?.stringValue
                self.sessionid = dict["sessionid"]?.stringValue ?? ""
                let imageData = Data(base64Encoded: imageStr ?? "")
                self.codeImageView.image = UIImage(data: imageData ?? Data())
            }
           
            
        }, failed: { (faildInfo,reCode,msg) -> (Void) in
            DispatchQueue.main.async {
                 MBProgressHUD.showMessage(faildInfo, to: self.bgView)
            }
        }) { () -> (Void) in
            DispatchQueue.main.async {
                MBProgressHUD.showMessage("刷新验证码失败。", to: self.bgView)
            }
        }
    }
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
}



